<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //筛选数组
        //要求:将数组[2,0,6,1,77,0,,52,25,7]中大于等于10的元素筛选出来,放入新数组
        //1.声明一个新的数组用于存放数据newArr
        //2.遍历原来的旧数组 找出大于等于10的元素
        //3.依次追加给新数组 newArr
        //法一:
        var newArr = [];
        var j = 0;
        var arr = [2, 0, 6, 1, 77, 0, 52, 25, 7];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] >= 10) {
                //新数组应该从0开始 依次递增 (这里就不做循环了,因为不确定大于等于10的个数)
                newArr[j] = arr[i];
                j++;
            }
        }
        console.log(newArr);
        //法二:
        var newArr = [];
        //刚开始为空 所以newArr.length就是 0
        var arr = [2, 0, 6, 1, 77, 0, 52, 25, 7];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] > 10 || arr[i] == 10) {
                //新数组索引号应该从0开始 依次递增
                newArr[newArr.length] = arr[i]; //newArr.length 因为前面数组为空,所以newArr.length起始是为0

            }
        }
        console.log(newArr);









        var arr = [];
        var j = 0;
        var arr1 = [2, 0, 6, 1, 77, 0, 25, 7];
        for (var i = 0; i < arr1.length; i++) {
            if (arr1[i] > 10 || arr1[i] == 10) {
                arr[j] = arr1[i];
                j++;
            }
        }
        console.log(arr);
    </script>
</head>

<body>

</body>

</html>